package com.onlyphoto.onlymall.mvp.model

import com.onlyphoto.onlymall.api.Urls
import com.onlyphoto.onlymall.base.BaseEntity
import com.onlyphoto.onlymall.base.BaseModel
import com.onlyphoto.onlymall.base.BaseObserver
import com.onlyphoto.onlymall.bean.request.CartGoodsBean
import com.onlyphoto.onlymall.bean.response.GoodsDetailsBean
import com.onlyphoto.onlymall.utils.ConfigUtil
import com.onlyphoto.onlymall.utils.RxTransformer


class MGoodsDetailsImpl : BaseModel() {
    fun requestDetails(baseObserver: BaseObserver<GoodsDetailsBean>, good_id: Int) {
        val url = ConfigUtil.instance.getUrl(Urls.GOODS)
        apiService().goodsDetials(url, good_id)
                .compose(RxTransformer.switchSchedulers(this))
                .subscribe(baseObserver)
    }

    fun add2Cart(baseObserver: BaseObserver<BaseEntity>, bean: CartGoodsBean) {
        val url = ConfigUtil.instance.getUrl(Urls.SHOPPING_CART)
        apiService().addToCart(url, bean.toMap())
                .compose(RxTransformer.switchSchedulers(this))
                .subscribe(baseObserver)
    }
}
